package com.lsh.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：LiuShihao
 * @date ：Created in 2021/11/15 3:15 下午
 * @desc ：
 */
@RestController
@RequestMapping
public class TimeController {

    private static final String Buried_point_num  = "buried_point_num";

    @Autowired
    StringRedisTemplate stringRedisTemplate;


    @GetMapping("/time")
    public Map timeServer(){
        stringRedisTemplate.opsForValue().increment(Buried_point_num);
        HashMap<String, Object> result = new HashMap<>();
        result.put("time", LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
        return result;

    }
    @GetMapping("/num")
    public Map num(){
        String num = stringRedisTemplate.opsForValue().get(Buried_point_num);
        HashMap<String, Object> result = new HashMap<>();
        result.put("访问次数", num);
        return result;

    }
}
